package logic.service;

import dao.WalletDAO;
import entity.Wallet;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import vo.IValueObject;
import vo.WalletVO;

/**
 *
 * @author Alexander
 */
public class WalletService implements IService {

    @Override
    public void persist(IValueObject vo, EntityManager em) {
        Wallet entity = new Wallet();
        entity.setId(((WalletVO) vo).getId());

        new WalletDAO().persist(entity, em);
    }

    @Override
    public IValueObject find(Object id, EntityManager em) {
        Wallet b = (Wallet) new WalletDAO().find(id, em);
        if (b != null) {
            return b.toVo();
        } else {
            return null;
        }
    }

    @Override
    public void update(IValueObject vo, EntityManager em) {
        Wallet entity = new Wallet();
        entity.setId(((WalletVO) vo).getId());

        new WalletDAO().update(entity, em);
    }

    @Override
    public void delete(Object id, EntityManager em) {
        new WalletDAO().delete(id, em);
    }

    @Override
    public List<IValueObject> getList(EntityManager em) {
        List<IValueObject> walletVO = new ArrayList<>();
        for (Object wallet : new WalletDAO().getList(em)) {
            walletVO.add(((Wallet) wallet).toVo());
        }
        return walletVO;
    }
}
